package com.qingke.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.qingke.mapper.StudentAccountMapper;
import com.qingke.mapper.StudentMapper;
import com.qingke.pojo.Student;
import com.qingke.pojo.StudentAccount;
import com.qingke.service.StudentService;
@Service("studentService")
public class StudentServiceImpl implements StudentService {
	private static Logger logger = Logger.getLogger(StudentServiceImpl.class);
	@Resource
	private StudentMapper stDao;
	@Resource
	private StudentAccountMapper staDao;


	public Student getStudentById(int studentId) {
		return stDao.selectByPrimaryKey(studentId);
	}

	public Student getStudentByStudentNumber(String studentNumber) {
		return stDao.selectByStudentNumber(studentNumber);
	}

	public boolean canStudentLogin(String studentNumber, String password) {
		int studentId=stDao.selectByStudentNumber(studentNumber).getId();
		List<StudentAccount> studentAccount=staDao.selectByPassword(password);
		for(StudentAccount sa:studentAccount){
			if(studentId==sa.getId()){
				return true;
			}
		}
		return false;
	}

	public boolean isStudentExisted(String studentNumber) {
		return stDao.selectByStudentNumber(studentNumber)!=null;
	}

	public int softDeleteEmployee(int employeeId) {
           return stDao.softDelete(employeeId);
	}

	public int updateStudentByPrimaryKey(Student record) {
		return stDao.updateByPrimaryKey(record);
	}

	public int saveStudent(Student student) {
		logger.debug("new student id ="+ student.getId());
		return stDao.insert(student);
	}

	public int saveStudentAccount(StudentAccount studentAccount) {
        logger.debug("new stduentAccount id ="+studentAccount.getId());
        return staDao.insert(studentAccount);
	}

	public int updateStudentAccountByPrimaryKey(StudentAccount record) {
		return staDao.updateByPrimaryKey(record);
	}

	public List<StudentAccount> listStudentAccountByPassword(String password) {
		return staDao.selectByPassword(password);
	}

	public StudentAccount getStudentAccountById(int studentAccountId) {
		return staDao.selectByPrimaryKey(studentAccountId);
	}

	public List<Student> listStudent() {
		List<Student> list=stDao.listStudent();
		for(Student student:list){
			System.out.println(student.getName());
	/*		if(student.getClazz().getClassStatus()!=null){
				
				System.out.println(student.getClazz().getClassStatus()); 
			}
			else if(student.getClazz().getClassType()!=null){
				
				System.out.println(student.getClazz().getClassType()); 
			}
			else if(student.getClazz().getHeadMaster()!=null){
				
				System.out.println(student.getClazz().getHeadMaster()); 
			}*/
		}
		return list;
		
	}

	public Student getStudentByStudentName(String studentName) {
		return stDao.selectByStudentName(studentName);
	}


}
